﻿package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.Party;

public class ActivityXmlparse {
	//private final static String TAG = "TopicXmlparse";
	private static ArrayList<Party> partys = null;
	private static  Party partybean = null;
	
	public static ArrayList<Party> getXml(InputStream inSteam) throws Exception{
		XmlPullParser xmpparse = Xml.newPullParser();   //得到解释器
		xmpparse.setInput(inSteam, "UTF-8");           //设置解释流
		int code = xmpparse.getEventType();            //得到节点信息
		String total = null;							//总记录数
		while(code!=XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				partys = new ArrayList<Party>();
				break;
			case XmlPullParser.START_TAG:
				if("total".equals(xmpparse.getName())){
					total = xmpparse.nextText();
				}
				if("party".equals(xmpparse.getName())){
					partybean = new Party();
					partybean.setTotal(Integer.parseInt(total));
				}
				if(partybean!=null){
					if("id".equals(xmpparse.getName())){
						String id = xmpparse.nextText();
						partybean.setId(Integer.parseInt(id));
					}
					if("title".equals(xmpparse.getName())){
						String title = xmpparse.nextText();
						partybean.setTitle(title);
					}
					if("top-image".equals(xmpparse.getName())){
						String topimage = xmpparse.nextText();
						partybean.setTopImage(topimage);
					}
					if("sdate".equals(xmpparse.getName())){
						String sdate = xmpparse.nextText();
						partybean.setsDate(sdate);
					}
					if("edate".equals(xmpparse.getName())){
						String edate = xmpparse.nextText();
						partybean.setEdate(edate);
					}
					if("price".equals(xmpparse.getName())){
						String price = xmpparse.nextText();
						partybean.setPrice(price);
					}
					if("author".equals(xmpparse.getName())){
						String author = xmpparse.nextText();
						partybean.setAuthor(author);
					}
					if("people".equals(xmpparse.getName())){
						String people = xmpparse.nextText();
						partybean.setPeople(people);
					}
					if("area".equals(xmpparse.getName())){
						String area = xmpparse.nextText();
						partybean.setArea(area);
					}
					if("description".equals(xmpparse.getName())){
						String description = xmpparse.nextText();
						partybean.setDescription(description);
					}
					if("activity".equals(xmpparse.getName())){
						String activity = xmpparse.nextText();
						partybean.setActivity(activity);
					}
					if("res-id".equals(xmpparse.getName())){
						String resid = xmpparse.nextText();
						partybean.setResid(resid);
					}
					if("res-title".equals(xmpparse.getName())){
						String restitle = xmpparse.nextText();
						partybean.setRestitle(restitle);
					}
					
				}
				break;
			case XmlPullParser.END_TAG:
				if("party".equals(xmpparse.getName())){
					partys.add(partybean);
					partybean = null;
				}
				break;
			}	
			code = xmpparse.next();
		}
		inSteam.close();
		return partys;
	}
}
